package modele;

import java.util.Collection;
import java.util.TreeSet;

public class Pays {
    private Collection <Dep> lesDeps = new TreeSet <Dep> ();
    private Collection <Spe> lesSpes = new TreeSet <Spe> ();
    
    public Pays() {
        lesDeps = PaysDAO.getLesDeps();
        lesSpes = PaysDAO.getLesSpes();
        Collection <Med> lesMeds = PaysDAO.getLesMeds();
        for (Med unMed: lesMeds) {
            for (Dep unDep: lesDeps) {
                String Dep = unDep.getNum();
                if (unMed.getDep().equals(Dep)) {
                    unDep.addMed(unMed);
                }
            }
            for (Spe uneSpe: lesSpes) {
                String Spe = uneSpe.getNom();
                if (Spe.equals(unMed.getSpe())) {
                    uneSpe.addMed(unMed);
                }
            }
        }
    }

    public Collection <Dep> getLesDeps() {
        return lesDeps;
    }
    
    public Dep getLeDep(String num) {
        for (Dep leDep:lesDeps) {
            if (leDep.getNum().equals(num)) {
                return leDep;
            }
        }
        return null;
    }
    
    public Collection <Med> getLesNoms(String nom) {
        Collection <Med> lesMeds=new TreeSet();
        for (Dep leDep:lesDeps) {
            for (Med leMed:leDep.getLesMeds()) {
                if (leMed.getNom().startsWith(nom)) {
                    lesMeds.add(leMed);
                }
            }
        }
        return lesMeds;
    }
    
    public Collection <Spe> getLesSpes() {
        return lesSpes;
    }
    
    public Spe getLaSpe(String nom) {
        for (Spe laSpe:lesSpes) {
            if (laSpe.getNom().equals(nom)) {
                return laSpe;
            }
        }
        return null;
    }
}